package utils;

import java.util.List;

public class DataInitializer {

  TextPrinter textPrinter;
  
  String [] weightNames;
  String [] criterionNames;
  Double [] weightValues;
  Double [] tresholdValues;
  Double [][] alternativesArray;
  String [] alternativesNames;

  public DataInitializer(String weightsFilePath, String dataFilePath) {
	  
	    textPrinter = TextPrinter.getInstance();
	    CsvParser parser = new CsvParser();

	    // put weights data into objects
	    List<String[]> weightsData = parser.parseCSVFile(weightsFilePath);
	     weightNames = weightsData.get(0);
	    String [] weightValuesString = weightsData.get(1);
	    weightValues = new Double [weightValuesString.length];
	    for(int i=0;i<weightValuesString.length;i++){
	    	weightValues[i] = Double.parseDouble(weightValuesString[i]);
	    }
	    textPrinter.printLine("Loaded weights:");
	    textPrinter.printLine(weightNames);
	    textPrinter.printLine(weightValuesString);
	    
	    
	    // put car data into objects    
	    List<String[]> carData = parser.parseCSVFile(dataFilePath);
	    alternativesArray = new Double[carData.size()-1][weightNames.length];
	    alternativesNames = new String[carData.size()];
	    criterionNames = carData.get(0);
	    textPrinter.printLine("Loaded cars:");
	    textPrinter.printLine(criterionNames);
	    for (int i = 1, k=0; i < carData.size(); i++,k++) {
	      String[] criterionValueString = carData.get(i);
	      alternativesNames[k] = criterionValueString[0];
	      textPrinter.printLine(criterionValueString);
	      for (int j = 1,m=0; j < criterionValueString.length; j++,m++) {
	        alternativesArray[k][m] = Double.parseDouble(criterionValueString[j]);
	      }
	    }
	}
  
  public DataInitializer(String weightsFilePath, String dataFilePath, String tresholdsFilePath) {
	  
    textPrinter = TextPrinter.getInstance();
    CsvParser parser = new CsvParser();

    
    // put weights data into objects
    List<String[]> weightsData = parser.parseCSVFile(weightsFilePath);
     weightNames = weightsData.get(0);
    String [] weightValuesString = weightsData.get(1);
    weightValues = new Double [weightValuesString.length];
    for(int i=0;i<weightValuesString.length;i++){
    	weightValues[i] = Double.parseDouble(weightValuesString[i]);
    }
    textPrinter.printLine("Loaded weights:");
    textPrinter.printLine(weightNames);
    textPrinter.printLine(weightValuesString);
    
    
    // put tresholds data into objects
    List<String[]> tresholdData = parser.parseCSVFile(tresholdsFilePath);
    String[] tresholdsValuesString = tresholdData.get(1);
    tresholdValues = new Double[tresholdsValuesString.length];
    for(int i=0;i<tresholdsValuesString.length;i++){
    	tresholdValues[i] = Double.parseDouble(tresholdsValuesString[i]);
    }
    textPrinter.printLine("Loaded tresholds");
    textPrinter.printLine(weightNames);
    textPrinter.printLine(tresholdsValuesString);

    
    // put car data into objects    
    List<String[]> carData = parser.parseCSVFile(dataFilePath);
    alternativesArray = new Double[carData.size()-1][weightNames.length];
    alternativesNames = new String[carData.size()];
    criterionNames = carData.get(0);
    textPrinter.printLine("Loaded cars:");
    textPrinter.printLine(criterionNames);
    for (int i = 1, k=0; i < carData.size(); i++,k++) {
      String[] criterionValueString = carData.get(i);
      alternativesNames[k] = criterionValueString[0];
      textPrinter.printLine(criterionValueString);
      for (int j = 1,m=0; j < criterionValueString.length; j++,m++) {
        alternativesArray[k][m] = Double.parseDouble(criterionValueString[j]);
      }
    }
}

public String[] getCriterionNames() {
	return criterionNames;
}

public String[] getAlternativesNames() {
	return alternativesNames;
}

public Double[] getWeightValues() {
	return weightValues;
}

public Double[][] getAlternativesArray() {
	return alternativesArray;
}

public Double[] getTresholdValues(){
	return tresholdValues;
}
  
  
//  public List<Alternative> getAlternatives() {
//    return alternatives;
//  }
//
//  public List<Weight> getWeights() {
//    return weights;
//  }

  
//  public DataInitializer() {
//	    textPrinter = TextPrinter.getInstance();
//	    CsvParser parser = new CsvParser();
//
//	    // put weights data into objects
//	    List<String[]> weightsData = parser.parseCSVFile("C://wagi.csv");
//	    String[] weightNames = weightsData.get(0);
//	    String[] weightValues = weightsData.get(1);
//	    textPrinter.printLine("Loaded weights:");
//	    textPrinter.printLine(weightNames);
//	    textPrinter.printLine(weightValues);
//	    weights = new ArrayList<Weight>();
//	    for (int i = 0; i < weightValues.length; i++) {
//	      weights.add(new Weight(weightNames[i], Double.parseDouble(weightValues[i])));
//	    }
//
//	    // put car data into objects
//	    alternatives = new ArrayList<Alternative>();
//	    List<String[]> carData = parser.parseCSVFile("C://dane1.csv");
//	    String[] criterionNames = carData.get(0);
//	    textPrinter.printLine("Loaded cars:");
//	    textPrinter.printLine(criterionNames);
//	    for (int i = 1; i < carData.size(); i++) {
//	      String[] criterionValueString = carData.get(i);
//	      textPrinter.printLine(criterionValueString);
//	      ArrayList<Criterion> criterias = new ArrayList<Criterion>();
//	      String carName = criterionValueString[0];
//	      for (int j = 1; j < criterionValueString.length; j++) {
//	        criterias.add(new Criterion(criterionNames[j], Double.parseDouble(criterionValueString[j]), Double.parseDouble(weightValues[j - 1])));
//	      }
//	      alternatives.add(new Alternative(carName, criterias));
//	    }
//
//	  }
}
